//
//  RNOLMoneyManagerSubViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/10.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMoneyManagerSubViewController.h"
#import "RNOLMoneyInvertTableViewCell.h"
#import "RNOLNewHandInvestViewController.h"
#import "RNOLClaimTransferViewController.h"

@interface RNOLMoneyManagerSubViewController ()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,assign) NSInteger dataCount;


@end

@implementation RNOLMoneyManagerSubViewController

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , KHIGHT-kTabBarHeight-kNavBarHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        adjustsScrollViewInsets_NO(_tableView, self);
        _tableView.tableFooterView = [UIView new];
//        [_tableView addFooterView];//有数据才添加上去
        _tableView.tableHeaderView = [UIView new];
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;
        [_tableView regsiterCellWithCellClass:[RNOLMoneyInvertTableViewCell class] isNib:YES];
//        [_tableView registerNib:[UINib nibWithNibName:@"RNOLMoneyInvertTableViewCell" bundle:nil] forCellReuseIdentifier:@"RNOLMoneyInvertTableViewCell"];
        [self.view addSubview: _tableView];
    }
    return _tableView;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KRandomColor;
    [self tableView];
    self.dataCount = 0;
    @weakify(self);
    [self.tableView addEmptyViewWithTipText:@"暂时没有数据" buttonText:@"重新加载" localImage:nil verticalOffset:0 tapClickAction: nil buttonAction:^{
        @strongify(self);
         self.dataCount = 20;
        [self.tableView reloadData];
    }];
}


#pragma mark -  UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RNOLMoneyInvertTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: [RNOLMoneyInvertTableViewCell cellReuseID]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 168;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.type == RNOLInvestTypeManagerMoney) {
        [self pushPageWithClass:[RNOLNewHandInvestViewController class]];
    }else{
       [self pushPageWithClass:[RNOLClaimTransferViewController class]];
    }
}

- (void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}



@end
